//
//  UIView+TransAnimation.swift
//  STMusic
//
//  Created by stoneobs on 17/5/12.
//  Copyright © 2017年 stoneobs. All rights reserved.
// //**********************转场动画 ***************************

import Foundation

public enum STTransAnimationType : String {
    
    
    
    case STkCATransitionPush = "kCATransitionPush";//推入
    case STkCATransitionMoveIn = "kCATransitionMoveIn";//移入
    case STkCATransitionReveal = "kCATransitionReveal";//截开效果
    case STkCATransitionFade = "kCATransitionFade";//渐入渐出效果
    
    case STcube = "cube";//立方体效果
    case STsuckEffect = "suckEffect";//三角效果
    case STrippleEffect = "rippleEffect";//水波抖动效果
    case STpageCurle = "pageCurl";// 上翻页
    
    case STpageUnCurl = "pageUnCurl";//下翻页
    case SToglFlip = "oglFlip";//上下翻转
    case STcameraIrisHollowOpen = "cameraIrisHollowOpen";//镜头效果
    case STcameraIrisHollowClose = "cameraIrisHollowClose";
}
extension UIView {
    
    
    
    func showTransAnimation(type:STTransAnimationType)  {
        
        let transion = CATransition.init();
        
        transion.type = type.rawValue;
        
        transion.duration = 1;
        
        transion.timingFunction = CAMediaTimingFunction.init(name: kCAMediaTimingFunctionEaseInEaseOut);
        
        self.layer.add(transion, forKey: nil);
    }
    func showTransAnimationWithTime(type:STTransAnimationType,duration:CFTimeInterval)  {
        
        let transion = CATransition.init();
        
        transion.type = type.rawValue;
        
        transion.duration = duration;
        
        transion.timingFunction = CAMediaTimingFunction.init(name: kCAMediaTimingFunctionEaseInEaseOut);
        
        self.layer.add(transion, forKey: nil);
    }
    func showRandromTransAnimation(){
    
        let array = [STTransAnimationType.STkCATransitionPush,STTransAnimationType.STkCATransitionMoveIn,STTransAnimationType.STkCATransitionReveal,STTransAnimationType.STkCATransitionFade,STTransAnimationType.STcube,STTransAnimationType.STsuckEffect,STTransAnimationType.STrippleEffect,STTransAnimationType.STpageCurle,STTransAnimationType.STpageUnCurl,STTransAnimationType.SToglFlip,STTransAnimationType.STcameraIrisHollowOpen,STTransAnimationType.STcameraIrisHollowClose];
        
        let index = array.count - 1;
        let num = Int(arc4random_uniform(UInt32(index)));
        
        let transion = CATransition.init();
        
        transion.type = array[num].rawValue;
        
        transion.duration = 1;
        
        transion.timingFunction = CAMediaTimingFunction.init(name: kCAMediaTimingFunctionEaseInEaseOut);
        
        self.layer.add(transion, forKey: nil);
    }
    
}
